package org.ccay.demo.grid.service.impl;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.ccay.core.base.BatchVO;
import org.ccay.core.base.PageVO;
import org.ccay.core.base.PagedResult;
import org.ccay.core.exception.ApplicationException;
import org.ccay.demo.grid.dao.IGridDao;
import org.ccay.demo.grid.service.IGridService;
import org.ccay.demo.grid.vo.GridVO;

/**
 * 
 * IGrid测试Service实现	
 */
@Named
public class GridService implements IGridService {
	
	@Inject
	private IGridDao demoDao;
	
	/**
	 * 分页数据
	 * @param queryDemo
	 * @param pageVO
	 * @return
	 */
	public PagedResult<GridVO> findPagedDemoList(GridVO queryGrid, PageVO pageVO) {
		return demoDao.findPagedDemoList(queryGrid, pageVO);
	}
	
	/**
	 * 滚动分页数据
	 * @param queryDemo
	 * @param pageVO
	 * @return
	 */
	public PagedResult<GridVO> findRangedDemoList(GridVO queryGrid, PageVO pageVO, String taxis, int totalRows) {
		return demoDao.findRangedDemoList(queryGrid, pageVO, taxis, totalRows);
	}

	/**
	 * 增加数据	
	 * @param newGrid
	 * @throws ApplicationException
	 */
	public void createDemo(GridVO newGrid) throws ApplicationException {
		demoDao.createDemo(newGrid);
	}

	/**
	 * 批量增加数据	
	 * @param newGrids
	 * @throws ApplicationException
	 */
	public void createDemos(List<GridVO> newGrids) throws ApplicationException {
		demoDao.createDemos(newGrids);
		
	}

	/**
	 * 批量删除数据	
	 * @param existedGrids
	 * @throws ApplicationException
	 */
	public void deleteDemos(List<GridVO> existedGrids) throws ApplicationException {
		demoDao.deleteDemos(existedGrids);
		
	}

	/**
	 * 批量修改数据	
	 * @param existedGrids
	 * @throws ApplicationException
	 */
	public void updateDemos(List<GridVO> existedGrids) throws ApplicationException {
		demoDao.updateDemos(existedGrids);
		
	}

	/**
	 * 批量操作数据	
	 * @param batchItems
	 * @throws ApplicationException
	 */
	public void batchOperation(BatchVO<GridVO> batchItems) throws ApplicationException {
		// 如果对象不为空 执行
		if(!batchItems.getItems2Create().isEmpty()){
			demoDao.createDemos(batchItems.getItems2Create());
		}
		// 如果对象不为空 执行
		if(!batchItems.getItems2Delete().isEmpty()){
			demoDao.deleteDemos(batchItems.getItems2Delete());
		}
		// 如果对象不为空 执行
		if(!batchItems.getItems2Update().isEmpty()){
			demoDao.updateDemos(batchItems.getItems2Update());
		}
	}

	public PagedResult<GridVO> findRangeDemoList(GridVO queryGrid, PageVO pageVO) {
		return demoDao.findRangeDemoList(queryGrid, pageVO);
	}
	
}
